﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Text;
using System.Data;

namespace PeisongWeb.admin
{
    public partial class complaintsList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("AD", 1))
                {
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("1=1");
            if (txt_orderno.Text.Trim()!="")
                where.AppendFormat("and orderno='{0}'",txt_orderno.Text.Trim());
            if (ddl_status.SelectedValue.Trim() != "")
                where.AppendFormat("and status='{0}'", ddl_status.SelectedValue.Trim());
            DataSet ds = logic.complaints.select(where.ToString(), "complaintId", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "details")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                getDetails(id);
                logic.complaints.updateStatus(id,"3");
                rptBind();
            }
        }
        protected void btn_Process_Click(object sender, EventArgs e)
        {
            ComplaintsEntity _cls = new ComplaintsEntity();
            _cls.ComplaintId = Convert.ToInt32(hd_complaintsid.Value);
            _cls.Process = txt_Process.Text;
            _cls.AdminId = logic.sysAdmin.AdminID;
            logic.complaints.updateProcess(_cls);
            rptBind();
        }
        void getDetails(int complaintid)
        {
            StringBuilder where = new StringBuilder();
            where.Append("complaintid=" + complaintid);
            DataSet ds = logic.complaints.select(where.ToString(), "complaintid", 1, 1);
            DataRow dr = ds.Tables[1].Rows[0];
            hd_complaintsid.Value = complaintid.ToString();
            lbl_orderNo.Text = dr["orderNo"].ToString();
            lbl_customerName.Text = dr["customerName"].ToString();
            lbl_company.Text = dr["company"].ToString();
            lbl_complaints.Text = dr["complaints"].ToString();
            lbl_inputDt.Text = dr["inputDt"].ToString();
            lbl_statusName.Text = dr["statusName"].ToString();
            if (dr["processDt"].ToString() != "")
            {
                li_admin.Visible = li_processDt.Visible=lbl_process.Visible = true;
                txt_Process.Visible=rfv_Process.Visible = btn_Process.Visible = false;
                lbl_process.Text = dr["process"].ToString();
                lbl_processDt.Text = dr["processDt"].ToString();
                lbl_adminName.Text = dr["adminName"].ToString();
            }
            else
            {
                txt_Process.Text = "";
                li_admin.Visible = li_processDt.Visible = lbl_process.Visible = false;
                txt_Process.Visible = rfv_Process.Visible = btn_Process.Visible = true;
            }
            complaints_details.Show();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
    }
}
